<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>APP版本</title>
    <link rel="icon" th:href="@{/img/icon.ico}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息(<b style="color: #1E9FFF;cursor: pointer">收起--展开</b>)</legend>
            <form class="layui-form layui-form-pane" id="search-form" lay-filter="search-form" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">APP名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="appName" autocomplete="off" class="layui-input" placeholder="请输入">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">版本号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="versionCode" autocomplete="off" class="layui-input" placeholder="请输入">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">版本名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="versionName" autocomplete="off" class="layui-input" placeholder="请输入">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">版本信息</label>
                        <div class="layui-input-inline">
                            <input type="text" name="versionInfo" autocomplete="off" class="layui-input" placeholder="请输入">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">强制更新</label>
                        <div class="layui-input-inline">
                            <select name="forceUpdate">
                                <option value="" selected>请选择</option>
                                <option th:each="item : ${update}" th:value="${item.code}" th:text="${item.name}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-sm layui-bg-blue" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索 </button>
                        <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary" lay-submit lay-filter="data-reset-btn"><i class="layui-icon">&#xe669;</i> 重 置 </button>
                    </div>
                </div>
            </form>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add" shiro:hasPermission="business:app-version:add"><i class="layui-icon">&#xe654;</i> 新增 </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            {{#
            var html='<span class="toolbar_span">';
                html+='<a src="javascript:void(0)" lay-event="delFlag" shiro:hasPermission="business:app-version:del">删除</a>';
                html+='<a src="javascript:void(0)" lay-event="update" shiro:hasPermission="business:app-version:edit"><div></div>编辑</a>';
                html+='<a src="javascript:void(0)" lay-event="download"><div></div>下载</a>';
                return html+'</span>'
            }}
        </script>
    </div>
</div>

<script type="text/javascript" th:src="@{/js/jquery-3.2.0.min.js}"></script>
<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:src="@{/js/common-table.js}"></script>

<script type="text/javascript" th:inline="javascript">

    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        var ctxPath = /*[[@{/}]]*/;
        var baseUrl = ctxPath + 'business/app-version/';

        var currTable = Asurplus.tableRender({
            table: table,
            url: baseUrl + 'list',
            cols: [
                [
                {field: '', title: '', type:'numbers', templet: function (d) {return d.LAY_TABLE_INDEX + 1;}},
                {field: 'appName', title: 'APP名称'},
                {field: 'versionCode', title: '版本号'},
                {field: 'versionName', title: '版本名称'},
                {field: 'versionInfo', title: '版本信息'},
                {field: 'forceUpdateText', title: '强制更新'},
                {field: 'downloadUrl', title: '下载地址'},
                {field: 'createTime', title: '创建时间'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center", fixed: 'right'}
            ]
            ]
        });

        // 表头工具
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {
                Asurplus.openLayer({
                    title: '新增',
                    content: baseUrl + 'add'
                }, () => {
                    currTable.reload();
                })
                return false;
            }
        });

        // 表行工具
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'update') {
                Asurplus.openLayer({
                    title: '修改',
                    content: baseUrl + 'update/' + data.id
                }, () => {
                    currTable.reload();
                })
                return false;
            } else if (obj.event === 'delFlag') {
                layer.confirm('确认删除', {
                    btn: ['确定'],
                    title: '提示'
                }, function(){
                    Asurplus.get({
                        url: baseUrl + 'del/' + data.id
                    }, () => {
                        currTable.reload();
                    });
                });
                return false;
            } else if (obj.event === 'download') {
                window.open(data.downloadUrl);
                return false;
            }
        });
    });
</script>

</body>
</html>